﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LunwenYun.Infrastructure.Entities.Repository;

namespace LunwenYun.Infrastructure.Entities.Entity
{
    public class ApplySheet : IAccessible<T_ApplySheet, ApplySheet>, ILogicEntity<T_ApplySheet, ApplySheet>
    {
        public int Id { get; set; }

        public int PerodicalId { get; set; }

        public string Username { get; set; }

        public string ApplyContent { get; set; }

        public DateTime ApplyDate { get; set; }
        /// <summary>
        /// 0:申请，1：同意，2：拒绝
        /// </summary>
        public int Status { get; set; }
        public DateTime HandleDate { get; set; }

        public Periodical Periodical { get; set; }
        public User User { get; set; }

        protected override void Covariant(T_ApplySheet model)
        {
            if (model != null)
            {
                this.Id = model.Id;
                this.PerodicalId = model.PerodicalId;
                this.Username = model.Username;
                this.ApplyContent = model.ApplyContent;
                this.ApplyDate = model.ApplyDate;
                this.Status = model.Status;
                this.HandleDate = model.HandleDate;
            }
        }

        protected override T_ApplySheet Inverter(ApplySheet model)
        {
            if (model != null)
            {
                return new T_ApplySheet()
                {
                    ApplyContent = model.ApplyContent,
                    ApplyDate = model.ApplyDate,
                    Id = model.Id,
                    PerodicalId = model.PerodicalId,
                    Username = model.Username,
                    HandleDate=model.HandleDate,
                    Status=model.Status
                };
            }
            return null;
        }

        public ApplySheet Set(T_ApplySheet dbModel)
        {
            Covariant(dbModel);
            return this;
        }

        public ApplySheet LoadPeriodical(T_Periodical t_Periodical)
        {
            if (t_Periodical != null)
            {
                Periodical = new Periodical().Set(t_Periodical);
            }
            return this;
        }
        public ApplySheet FindPeriodical()
        {
            if (this.PerodicalId > 0)
            {
                this.Periodical = new Periodical().Find(this.PerodicalId.ToString());
            }
            return this;
        }

        public ApplySheet LoadUser(T_User t_user)
        {
            if (t_user != null)
            {
                User = new User().Set(t_user);
            }
            return this;
        }
        public ApplySheet FindUser()
        {
            if (!String.IsNullOrEmpty(this.Username))
            {
                this.User = new User().Find(this.Username);
            }
            return this;
        }
    }
}
